home *** CD-ROM | disk | FTP | other *** search
- // Chapter 2 - Programming exercise 2
- #include "iostream.h"
-
- class animal {
- public:
- int weight;
- int feet;
- int number_of_ways;
- };
-
- main()
- {
- animal dog1, dog2, chicken;
- animal cat1;
- class animal cat2;
-
- dog1.weight = 15;
- dog2.weight = 37;
- chicken.weight = 3;
-
- dog1.feet = 4;
- dog2.feet = 4;
- chicken.feet = 2;
-
- dog1.number_of_ways = 17;
- dog2.number_of_ways = 21;
- chicken.number_of_ways = 7;
-
- cout << "The weight of dog1 is " << dog1.weight << "\n";
- cout << "The weight of dog2 is " << dog2.weight << "\n";
- cout << "The weight of chicken is " << chicken.weight << "\n";
-
- cout << "Dog1 can do things " << dog1.number_of_ways
- << " different ways\n";
- cout << "The chicken can do things " << chicken.number_of_ways
- << " different ways\n";
- }
-
-
-
-
- // Result of execution
- //
- // The weight of dog1 is 15
- // The weight of dog2 is 37
- // The weight of chicken is 3
- // Dog1 can do things 17 different ways
- // The chicken can do things 7 different ways
-